# !/usr/bin/env python
# -*- coding: utf-8 -*-
# 装饰器

import time


# 计时器
def timer(func):
    def wrapper(*args, **kwargs):
        start_time = time.time()
        result = func(*args, **kwargs)
        end_time = time.time()
        print(f"{func.__name__} took {end_time - start_time:.2f} seconds to execute.")
        return result

    return wrapper


# 参数校验
def validate(func):
    def wrapper(*args, **kwargs):
        # Your data validation logic here
        # print(type(args[0]))
        if type(args[0]) == str:
            return func(*args, **kwargs)
        else:
            # raise ValueError("Invalid data. Please check your inputs.")
            print("Invalid data. Please check your inputs.")

    return wrapper


def log_result(func):
    def wrapper(*args, **kwargs):
        result = func(*args, **kwargs)
        print(f"{func.__name__} - Result: {result}\n")
        return result

    return wrapper


@timer
def time_func():
    time.sleep(0.1)


@validate
def validate_func(a: str):
    print(a)


@log_result
def log_sum_func(*nums):
    s = 0
    for num in nums:
        s += num
    return s


if __name__ == '__main__':
    time_func()
    validate_func(1)
    log_sum_func(1, 2, 3)
